package com.px.user.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.sql.Timestamp;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "sms")
@org.hibernate.annotations.Table(appliesTo = "sms", comment = "短信表")
public class Sms {

    @Id
    @ApiModelProperty(value = "主键", hidden = true)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @NotNull(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "电话号码", example = "152...")
    @Column(columnDefinition = "varchar(32) comment '电话号码'")
    private String phone;

    @ApiModelProperty(value = "短信验证码", example = "66521", hidden = true)
    @Column(columnDefinition = "varchar(16) comment '短信验证码'")
    private String sms;

    @ApiModelProperty(value = "成功状态：0#成功", hidden = true)
    @Column(columnDefinition = "varchar(8) comment '成功状态：0#成功'")
    private String code;

    @ApiModelProperty(value = "短信ID", hidden = true)
    @Column(columnDefinition = "varchar(64) comment '短信ID'")
    private String msgId;

    @ApiModelProperty(value = "发送时间", hidden = true)
    @Column(columnDefinition = "varchar(32) comment '发送时间'")
    private String time;

    @ApiModelProperty(value = "异常信息", hidden = true)
    @Column(columnDefinition = "varchar(128) comment '异常信息'")
    private String errorMsg;

    @ApiModelProperty(value = "有效：0#有效,1#无效", hidden = true)
    @Column(columnDefinition = "bit default 0 comment '有效：0#有效,1#无效'")
    private Integer valid;

    @ApiModelProperty(value = "创建时间", hidden = true)
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    @Generated(GenerationTime.INSERT)
    private Timestamp createTime;

    @ApiModelProperty(value = "更新时间", hidden = true)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'", insertable = false, updatable = false)
    @Generated(GenerationTime.INSERT)
    private Timestamp updateTime;
}
